package org.marsdonne.audits.artemis;

import org.marsdonne.audits.ChangeAuditable;
import org.marsdonne.audits.Changed;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jms.core.JmsTemplate;

import javax.annotation.Resource;

public class ChangeAuditImpl implements ChangeAuditable {

    @Value("${spring.application.name}")
    private String serviceId;

    @Value("${audits.artemis.channel.changed:channels.audits.changed}")
    private String channel;

    @Resource
    private JmsTemplate auditsJmsTemplate;

    @Override
    public void changed(Changed changed) {
        changed.setServiceId(serviceId);
        auditsJmsTemplate.send(channel, session -> session.createObjectMessage(changed));
    }
}
